package com.example.administrator.xxnapp.fragment.event;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.xxnapp.R;
import com.example.administrator.xxnapp.bean.EventBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.mdruby.baselibrary.utils.DateUtil;

/**
 * Created by Went_Gone on 2018/5/8.
 */

public class RVEventAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<EventBean> mDatas;

    public RVEventAdapter(Context context, List<EventBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    public RVEventAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new RVEventViewHolder(LayoutInflater.from(context).inflate(R.layout.item_event_layout,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof RVEventViewHolder){
            ((RVEventViewHolder) holder).bindView(position);
        }
    }

    @Override
    public int getItemCount() {
        return mDatas == null?0:mDatas.size();
    }

    private class RVEventViewHolder extends RecyclerView.ViewHolder{
        private TextView mTVDateTop;
        TextView mTVDateBottom;
        TextView mTVContent;
        TextView mTVDescribe;
        private View mViewVerticalBottom;

        public RVEventViewHolder(View itemView) {
            super(itemView);
            mTVDateTop = itemView.findViewById(R.id.item_event_layout_TV_Date_Top);
            mTVDateBottom = itemView.findViewById(R.id.item_event_layout_TV_Date_Bottom);
            mTVContent = itemView.findViewById(R.id.item_event_layout_TV_Content);
            mTVDescribe = itemView.findViewById(R.id.item_event_layout_TV_Describe);
            mViewVerticalBottom = itemView.findViewById(R.id.item_event_layout_View_Vertical_Bottom);
        }

        private void bindView(int position){
            EventBean bean = mDatas.get(position);
            mTVDateTop.setText(DateUtil.getDate(bean.getCreateDate(),"MM-dd"));
            mTVDateBottom.setText(DateUtil.getDate(bean.getCreateDate(),"yyyy年"));
            mTVContent.setText(bean.getContent());
            mTVDescribe.setText(bean.getDescribe());
            mViewVerticalBottom.setVisibility(position == mDatas.size()-1?View.INVISIBLE:View.VISIBLE);
        }
    }
}
